<template>
  <div>
 <h2>会员添加</h2>
 <hr>
 <table>
  <tr>
    <td>会员名称:</td>
    <td>
      <input type="text" v-model="state.name">
    </td>
  </tr>
  <tr>
    <td>会员密码:</td>
    <td>
      <input type="text" v-model="state.pwd">
    </td>
  </tr>
  <tr>
    <td>会员年龄:</td>
    <td>
      <input type="text" v-model="state.age">
    </td>
  </tr>
  <tr>
    <td>会员电话:</td>
    <td>
      <input type="text" v-model="state.phone">
    </td>
  </tr>
  <tr>
    <td>会员性别:</td>
    <td>
      <input type="text" v-model="state.sex">
    </td>
  </tr>
  <tr>
      <td colspan="2">
    <input type="button" value="添加" @click="MemberAdd">
      </td>
    </tr>
 </table>
  </div>
</template>

<script setup lang="ts">
import{reactive,toRefs,onMounted} from 'vue';
import{useRouter,useRoute} from 'vue-router';
import axios from 'axios';

const router=useRouter();
const route=useRoute();

let data:any=reactive({
  state:{
    name:'',
    pwd:'',
    age:0,
    phone:0,
    sex:''
  }

})
let {state}=toRefs(data);

function MemberAdd(){
  let obj={
    name:state.value.name,
    pwd:state.value.pwd,
    age:state.value.age,
    phone:state.value.phone,
    sex:state.value.sex
  }
  axios({
    url:'https://localhost:7280/api/Member/MemberAdd',
    method:'post',
    data:obj
  })
  .then(res=>{
    if(res.data.data>0)
  {
    alert('添加成功')
    router.push('/MemberAdd')
  }
  else{
    alert('添加失败')
    return
  }
  })
  .catch(err=>{
    console.log(err)
  })
}
</script>

<style scoped>

</style>